class MaxQueue {

    Deque<Integer> deque;
    Queue<Integer> queue;


    public MaxQueue() {
        deque = new LinkedList<>();
        queue = new LinkedList<>();
    }
    
    public int max_value() {
        if(queue.isEmpty()) {
            return -1;
        }
        return deque.peekFirst();
    }
    
    public void push_back(int value) {
        if(deque.isEmpty()) {
            deque.addLast(value);
        }else {
            while(!deque.isEmpty() && value > deque.peekLast()) {
                deque.removeLast();
            }
            deque.addLast(value);
        }
        queue.add(value);
    }
    
    public int pop_front() {
        if(queue.isEmpty()) {
            return -1;
        }
        if(deque.peekFirst().equals(queue.peek())) {
            deque.removeFirst();
        }
        return queue.poll();
    }
}

/**
 * Your MaxQueue object will be instantiated and called as such:
 * MaxQueue obj = new MaxQueue();
 * int param_1 = obj.max_value();
 * obj.push_back(value);
 * int param_3 = obj.pop_front();
 */